<?php include 'head.php'; ?>

    <title>用户资料</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/component/pear/css/pear.css" />
</head>

<body class="pear-container">
    <div class="layui-card">
        <div class="layui-card-header">用户资料</div>
        <div class="layui-card-body">
            <form class="layui-form" action="" onsubmit="return false">
                <div class="layui-form-item">
                    <label class="layui-form-label">姓名(用户名)</label>
                    <div class="layui-input-block">
                        <input type="text" id="name" readonly class="layui-input" value="<?php echo $_SESSION['user']['name']; ?>">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">性别</label>
                    <div class="layui-input-block">
                        <?php
                        switch ($_SESSION['user']['gender']) {
                            case '男':
                                echo '<input type="radio" name="gender" value="男" title="男" checked><input type="radio" name="gender" value="女" title="女"><input type="radio" name="gender" value="保密" title="保密">';
                                break;

                            case '女':
                                echo '<input type="radio" name="gender" value="男" title="男"><input type="radio" name="gender" value="女" title="女" checked><input type="radio" name="gender" value="保密" title="保密">';
                                break;

                            default:
                                echo '<input type="radio" name="gender" value="男" title="男"><input type="radio" name="gender" value="女" title="女"><input type="radio" name="gender" value="保密" title="保密" checked>';
                                break;
                        }
                        ?>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">生日</label>
                    <div class="layui-input-block">
                        <input type="text" name="birthday" lay-verify="date" id="date" placeholder="请输入生日" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">电话</label>
                    <div class="layui-input-block">
                        <input type="number" name="tel" lay-verify="phone" placeholder="请输入电话" class="layui-input" value="<?php echo $_SESSION['user']['tel']; ?>">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">邮箱</label>
                    <div class="layui-input-block">
                        <input type="email" name="mail" lay-verify="email" placeholder="请输入邮箱" class="layui-input" value="<?php echo $_SESSION['user']['mail']; ?>">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">QQ</label>
                    <div class="layui-input-block">
                        <input type="number" name="qq" lay-verify="number" placeholder="请输入QQ" class="layui-input" value="<?php echo $_SESSION['user']['qq']; ?>">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">微信</label>
                    <div class="layui-input-block">
                        <input type="text" name="wechat" placeholder="请输入微信" class="layui-input" value="<?php echo $_SESSION['user']['wechat']; ?>">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">地址</label>
                    <div class="layui-input-block">
                        <input type="text" name="address" placeholder="请输入地址" class="layui-input" value="<?php echo $_SESSION['user']['address']; ?>">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="pear-btn pear-btn-primary" lay-submit lay-filter="formDemo">立即提交</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <script src="/component/layui/layui.js"></script>
    
<script src="/component/pear/pear.js"></script>
    <script>
        layui.use(['form', 'layer', 'jquery', 'laydate', 'button', 'popup'], function() {
            var $ = layui.jquery,
                form = layui.form,
                layer = layui.layer,
                laydate = layui.laydate,
                button = layui.button,
                popup = layui.popup;

            $('#name').focus(function() {
                layer.tips('不可编辑，如需编辑请联系管理员', '#name', {
                    tips: [3, '#ff6700'],
                    time: 3000
                });
            });

            laydate.render({
                elem: '#date',
                value: '<?php echo $_SESSION['user']['birthday']; ?>'
            });

            // 修改信息
            window.onkeypress = function(e) { if (e.keyCode == 13) { $('[lay-submit]').click(); } }
form.on('submit(formDemo)', function(data) {

                /// 验证
                console.log(data.field);

                /// 按钮加载动画
                var load = button.load({
                    elem: '.pear-btn-primary'
                });
                /// 提交
                $.ajax({
                    url: './ajax.php?act=profile',
                    type: "POST",
                    timeout: "5000",
                    data: data.field,
                    success: function(data) {
                        load.stop();
                        if (data.code == "200") {
                            popup.success(data.msg);
                        } else {
                            popup.failure(data.msg);
                        }
                    },
                    error: function(XMLResponse) {
                        load.stop();
                        popup.failure("提交异常");
                    }
                });

                return false;
            });
        });
    </script>
</body>

</html>